<?php
/**
 * Created by PhpStorm.
 * User: qufan
 * Date: 2016/12/17 0017
 * Time: 10:46
 */

namespace Common\Logic;


class DatumDicLogic
{

    public static function getDatumDicTree(){
        $tree = array();
        $where['state'] = 1;
        $field = 'state';
        $datumDicClassList = M('DatumDicClass')->field($field, true)->where($where)->select();
        $datumDicTypeList = M('DatumDicType')->field($field, true)->where($where)->select();

        $refer = array();

        foreach ($datumDicClassList as $key => $data){
            $datumDicClassList[$key]['text'] = $data['type_name'];
            $tree[] = & $datumDicClassList[$key];
            $refer[$data['class_id']] = & $datumDicClassList[$key];
        }

        foreach ($datumDicTypeList as $key => $data){
            $datumDicTypeList[$key]['text'] = $data['type_name'];
            $parentId = $data['class_id'];
            if(isset($refer[$parentId])){
                $parent =& $refer[$parentId];
                $parent['nodes'][] = & $datumDicTypeList[$key];
            }
        }

        return $tree;
    }

}